package org.algorithm.Backtracking.leetcode78;

import java.util.ArrayList;
import java.util.List;

public class Solution2 {

    List<List<Integer>> res = new ArrayList<>();
    List<Integer> item = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        backtracking(nums,0);
        return res;
    }

    private void backtracking(int[] nums, int index) {

        res.add(new ArrayList<>(item));

        for (int i = index; i < nums.length; i++) {
            item.add(nums[i]);
            backtracking(nums,i+1);
            item.remove(item.size()-1);
        }

    }
}
